package com.gitee.l0km.beanfilter.core;

import java.util.Collections;
import java.util.Set;

public interface IFilterContainer {

	/**
	 * 获取 {@code phase}指定编解码阶段及 {@code scope} 指定范围的过滤器<br>
	 * phase 必须为 {@link CodecPhase#SERIALIZATION}或{@link CodecPhase#DESERIALIZATION}
	 * @param phase 
	 * @param scope
	 */
	ICombinedFilter getFilter(CodecPhase phase, CodecScope scope);

	/**
	 * 获取 {@code phase}指定编解码阶段及 {@code scope} 指定范围的过滤器<br>
	 * @param phase 必须为 {@link CodecPhase#SERIALIZATION}或{@link CodecPhase#DESERIALIZATION}
	 * @param scope 必须为 {@link CodecScope#FASTJSON},{@link CodecScope#JACKSON}或{@link CodecScope#THRIFT}
	 */
	ICombinedFilter getScenceFilter(CodecPhase phase, CodecScope scope);

	/**
	 * 返回指定编/解码阶段和作用范围过滤器关联的所有类型
	 * @param phase
	 * @param scope
	 */
	Set<Class<?>> associateClasses(CodecPhase phase, CodecScope scope);

	boolean isEmpty();
	
	public static final IFilterContainer DEFAULT_INSTANCE = new DefaultFilterContainer();
	public static class DefaultFilterContainer implements IFilterContainer{

		@Override
		public ICombinedFilter getFilter(CodecPhase phase, CodecScope scope) {
			return ICombinedFilter.DEFAULT_INSTANCE;
		}

		@Override
		public ICombinedFilter getScenceFilter(CodecPhase phase, CodecScope scope) {
			return ICombinedFilter.DEFAULT_INSTANCE;
		}

		@Override
		public Set<Class<?>> associateClasses(CodecPhase phase, CodecScope scope) {
			return Collections.emptySet();
		}

		@Override
		public boolean isEmpty() {
			return true;
		}
		@Override
		public int hashCode() {
			return getClass().hashCode();
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			return getClass() == obj.getClass();
		}
	}
}
